package ${packagePrefix}.application.executor.${tableName?lower_case};

import ${packagePrefix}.application.assembler.${domainObjectName}Assembler;
import ${packagePrefix}.client.dto.command.${domainObjectName}AddCmd;
import ${packagePrefix}.domain.gateway.${domainObjectName}Gateway;
import ${packagePrefix}.domain.model.${tableName?lower_case}.${domainObjectName};
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.alibaba.cola.dto.Response;
import com.alibaba.cola.dto.SingleResponse;
import org.springframework.transaction.annotation.Transactional;

/**
 * ${entityComment}新增命令执行器
 */
@Component
public class ${domainObjectName}AddCmdExe {

    @Autowired
    private ${domainObjectName}Gateway ${domainObjectName?uncap_first}Gateway;

    @Autowired
    private ${domainObjectName}Assembler ${domainObjectName?uncap_first}Assembler;

    /**
     * 执行${entityComment}新增命令
     *
     * @param cmd ${entityComment}新增命令
     * @return 执行结果
     */
    @Transactional
    public SingleResponse<Long> execute(${domainObjectName}AddCmd cmd) {
        // 转换为领域实体
        ${domainObjectName} ${domainObjectName?uncap_first} = ${domainObjectName?uncap_first}Assembler.toEntity(cmd);
        
        // 进行业务规则校验
        ${domainObjectName?uncap_first}.checkValid();
        
        // 保存领域实体
        Long id = ${domainObjectName?uncap_first}Gateway.save(${domainObjectName?uncap_first});
        
        return SingleResponse.of(id);
    }
} 